home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 February / SGI IRIX 6.5 Complementary Applications 2004 February.iso / dist / cde.idb / usr / dt / share / examples / dthelp / HourGlass.c.z / HourGlass.c
Encoding:
C/C++ Source or Header  |  2003-11-18  |  7.8 KB  |  284 lines

  1. /*
  2.  * HourGlass.c
  3.  *
  4.  * Copyright 2000, Silicon Graphics, Inc.
  5.  * ALL RIGHTS RESERVED
  6.  * 
  7.  * UNPUBLISHED -- Rights reserved under the copyright laws of the United
  8.  * States.   Use of a copyright notice is precautionary only and does not
  9.  * imply publication or disclosure.
  10.  *
  11.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  12.  * Use, duplication or disclosure by the Government is subject to restrictions
  13.  * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  14.  * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  15.  * in similar or successor clauses in the FAR, or the DOD or NASA FAR
  16.  * Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  17.  * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  18.  *
  19.  * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  20.  * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  21.  * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  22.  * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  23.  * GRAPHICS, INC.
  24.  */
  25. /* $XConsortium: HourGlass.c /main/cde1_maint/1 1995/07/17 21:00:17 drk $ */
  26. /************************************<+>*************************************
  27.  ****************************************************************************
  28.  **
  29.  **   File:        HourGlass.c
  30.  **
  31.  **   Project:     CDE dthelpdemo sample program.
  32.  **
  33.  **   Description: This module contains a simple function for
  34.  **                creating an hourglass cursor.
  35.  **
  36.  **  (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
  37.  **      Hewlett-Packard Company
  38.  **  (c) Copyright 1993, 1994 International Business Machines Corp.
  39.  **  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  40.  **  (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
  41.  **      Novell, Inc.
  42.  **
  43.  **
  44.  **
  45.  ****************************************************************************
  46.  ************************************<+>*************************************/
  47.  
  48.  
  49. #include <X11/Xlib.h>
  50. #include <X11/Intrinsic.h>
  51.  
  52. #define time32_width 32
  53. #define time32_height 32
  54. #define time32_x_hot 15
  55. #define time32_y_hot 15
  56. static unsigned char time32_bits[] = {
  57.    0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
  58.    0x8c, 0x00, 0x00, 0x31, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
  59.    0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
  60.    0x8c, 0x00, 0x00, 0x31, 0x0c, 0x7f, 0xfe, 0x30, 0x0c, 0xfe, 0x7f, 0x30,
  61.    0x0c, 0xfc, 0x3f, 0x30, 0x0c, 0xf8, 0x1f, 0x30, 0x0c, 0xe0, 0x07, 0x30,
  62.    0x0c, 0x80, 0x01, 0x30, 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x60, 0x06, 0x30,
  63.    0x0c, 0x18, 0x18, 0x30, 0x0c, 0x04, 0x20, 0x30, 0x0c, 0x02, 0x40, 0x30,
  64.    0x0c, 0x01, 0x80, 0x30, 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x80, 0x01, 0x32,
  65.    0x4c, 0xc0, 0x03, 0x32, 0x4c, 0xf0, 0x1f, 0x32, 0x4c, 0xff, 0xff, 0x32,
  66.    0xcc, 0xff, 0xff, 0x33, 0x8c, 0xff, 0xff, 0x31, 0xfe, 0xff, 0xff, 0x7f,
  67.    0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00};
  68.  
  69. #define time32m_width 32
  70. #define time32m_height 32
  71. static unsigned char time32m_bits[] = {
  72.    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  73.    0xcf, 0x00, 0x00, 0xf3, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
  74.    0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
  75.    0xce, 0x00, 0x00, 0x73, 0x8e, 0x7f, 0xfe, 0x71, 0x0e, 0xff, 0xff, 0x70,
  76.    0x0e, 0xfe, 0x7f, 0x70, 0x0e, 0xfc, 0x3f, 0x70, 0x0e, 0xf8, 0x1f, 0x70,
  77.    0x0e, 0xe0, 0x07, 0x70, 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0x78, 0x1e, 0x70,
  78.    0x0e, 0x1c, 0x38, 0x70, 0x0e, 0x06, 0x60, 0x70, 0x0e, 0x03, 0xc0, 0x70,
  79.    0x8e, 0x01, 0x80, 0x71, 0xce, 0x00, 0x00, 0x73, 0x6e, 0x80, 0x01, 0x76,
  80.    0x6e, 0xc0, 0x03, 0x76, 0x6e, 0xf0, 0x1f, 0x76, 0x6e, 0xff, 0xff, 0x76,
  81.    0xee, 0xff, 0xff, 0x77, 0xcf, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff,
  82.    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  83.  
  84.  
  85. #define time16_x_hot 7
  86. #define time16_y_hot 7
  87. #define time16_width 16
  88. #define time16_height 16
  89. static unsigned char time16_bits[] = {
  90.    0x00, 0x00, 0xfe, 0x7f, 0x14, 0x28, 0x14, 0x28, 0x14, 0x28, 0x24, 0x24,
  91.    0x44, 0x22, 0x84, 0x21, 0x84, 0x21, 0x44, 0x22, 0x24, 0x24, 0x14, 0x28,
  92.    0x94, 0x29, 0xd4, 0x2b, 0xfe, 0x7f, 0x00, 0x00};
  93.  
  94. #define time16m_width 16
  95. #define time16m_height 16
  96. static unsigned char time16m_bits[] = {
  97.    0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
  98.    0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
  99.    0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff};
  100.  
  101.  
  102. /********    End Public Function Declarations    ********/
  103.  
  104. /*************************************<->*************************************
  105.  *
  106.  *  Cursor GetHourGlassCursor ()
  107.  *
  108.  *
  109.  *  Description:
  110.  *  -----------
  111.  *  Builds and returns the appropriate Hourglass cursor
  112.  *
  113.  *
  114.  *  Inputs:
  115.  *  ------
  116.  *  dpy    = display
  117.  * 
  118.  *  Outputs:
  119.  *  -------
  120.  *  Return = cursor.
  121.  *
  122.  *  Comments:
  123.  *  --------
  124.  *  None. (None doesn't count as a comment)
  125.  * 
  126.  *************************************<->***********************************/
  127. static Cursor GetHourGlassCursor(
  128.   Display *dpy)
  129.  
  130. {
  131.     char        *bits;
  132.     char        *maskBits;
  133.     unsigned int width;
  134.     unsigned int height;
  135.     unsigned int xHotspot;
  136.     unsigned int yHotspot;
  137.     Pixmap       pixmap;
  138.     Pixmap       maskPixmap;
  139.     XColor       xcolors[2];
  140.     int          scr;
  141.     unsigned int cWidth;
  142.     unsigned int cHeight;
  143.     int         useLargeCursors = 0;
  144.     static Cursor waitCursor=0;
  145.  
  146.  
  147.     if (waitCursor != 0)
  148.       return(waitCursor);
  149.  
  150.     if (XQueryBestCursor (dpy, DefaultRootWindow(dpy), 
  151.     32, 32, &cWidth, &cHeight))
  152.     {
  153.     if ((cWidth >= 32) && (cHeight >= 32))
  154.     {
  155.         useLargeCursors = 1;
  156.     }
  157.     }
  158.  
  159.     if (useLargeCursors)
  160.     {
  161.     width    = time32_width;
  162.     height   = time32_height;
  163.     bits     = (char *) time32_bits;
  164.     maskBits = (char *) time32m_bits;
  165.     xHotspot = time32_x_hot;
  166.     yHotspot = time32_y_hot;
  167.     }
  168.     else
  169.     {
  170.     width    = time16_width;
  171.     height   = time16_height;
  172.     bits     = (char *) time16_bits;
  173.     maskBits = (char *) time16m_bits;
  174.     xHotspot = time16_x_hot;
  175.     yHotspot = time16_y_hot;
  176.     }
  177.  
  178.     pixmap = XCreateBitmapFromData (dpy, 
  179.              DefaultRootWindow(dpy), bits, 
  180.              width, height);
  181.  
  182.   
  183.     maskPixmap = XCreateBitmapFromData (dpy, 
  184.              DefaultRootWindow(dpy), maskBits, 
  185.              width, height);
  186.  
  187.     xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
  188.     xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
  189.  
  190.     XQueryColors (dpy, 
  191.           DefaultColormapOfScreen(DefaultScreenOfDisplay
  192.                       (dpy)), xcolors, 2);
  193.  
  194.     waitCursor = XCreatePixmapCursor (dpy, pixmap, maskPixmap,
  195.                       &(xcolors[0]), &(xcolors[1]),
  196.                       xHotspot, yHotspot);
  197.     XFreePixmap (dpy, pixmap);
  198.     XFreePixmap (dpy, maskPixmap);
  199.  
  200.     return (waitCursor);
  201. }
  202.  
  203.  
  204. /*************************************<->*************************************
  205.  *
  206.  *  void TurnOnHourGlass
  207.  *
  208.  *
  209.  *  Description:
  210.  *  -----------
  211.  *  sets the window cursor to an hourglass
  212.  *
  213.  *
  214.  *  Inputs:
  215.  *  ------
  216.  *  w   = Widget
  217.  *
  218.  *  Outputs:
  219.  *  -------
  220.  *  None
  221.  *
  222.  *  Comments:
  223.  *  --------
  224.  *  None. (None doesn't count as a comment)
  225.  *
  226.  *************************************<->***********************************/
  227. void TurnOnHourGlass(
  228.         Widget w)
  229. {
  230.     Cursor cursor;
  231.     
  232.     cursor = GetHourGlassCursor(XtDisplay(w));
  233.  
  234.     XDefineCursor(XtDisplay(w), XtWindow(w), cursor);
  235.     XFlush(XtDisplay(w));
  236. }
  237.  
  238.  
  239. /*************************************<->*************************************
  240.  *
  241.  *  void TurnOffHourGlass
  242.  *
  243.  *
  244.  *  Description:
  245.  *  -----------
  246.  *  Removed the hourglass cursor from a window
  247.  *
  248.  *
  249.  *  Inputs:
  250.  *  ------
  251.  *  w = Widget
  252.  *
  253.  *  Outputs:
  254.  *  -------
  255.  *  None
  256.  *
  257.  *  Comments:
  258.  *  --------
  259.  *  None. (None doesn't count as a comment)
  260.  *
  261.  *************************************<->***********************************/
  262. void TurnOffHourGlass(
  263.         Widget w)
  264.  
  265. {
  266.    
  267.     XUndefineCursor(XtDisplay(w), XtWindow(w));
  268.     XFlush(XtDisplay(w));
  269. }
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.